package com.itestor.iptv.modules.common.actions;



import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import com.itestor.iptv.global.actions.AbstractPagedQueryAction;
import com.itestor.iptv.global.bean.AbstractPagedQuery;
import com.itestor.iptv.modules.common.bean.SystemLogQuery;
import com.itestor.iptv.modules.common.service.SystemLogService;

/**
 * 
 * @author Mr.li
 * 
 */
public class SystemLogQueryAction extends AbstractPagedQueryAction {

    /**
     * Logger for this class.
     */
    private static final Logger logger = Logger
            .getLogger(SystemLogQueryAction.class);

    private SystemLogService systemLogService;
    
    private static final SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    @SuppressWarnings("unchecked")
    public AbstractPagedQuery doPagedQuery(ActionForm form,
            HttpServletRequest request, int pagerCount, int pagerOffset)
            throws Exception {
        logger.info("log query ...");        
        
        String startTime = request.getParameter("startTime");
        String endTime = request.getParameter("endTime");        
        String logType=request.getParameter("logType");
        String logDesc=request.getParameter("logDesc");
        
        SystemLogQuery loginLogQuery = new SystemLogQuery();
        
        if (!StringUtils.isEmpty(startTime)) {
            loginLogQuery.setStartTime(sdf.parse(startTime));
            request.setAttribute("startTime", startTime);
        }
        
        if (!StringUtils.isEmpty(endTime)) {
            loginLogQuery.setEndTime(sdf.parse(endTime));
            request.setAttribute("endTime", endTime);
        }
        
        if (!StringUtils.isEmpty(logType)) {
            loginLogQuery.setLogType(Integer.parseInt(logType));
            request.setAttribute("logType", logType);
        }
        
        if (!StringUtils.isEmpty(logDesc)) {
            loginLogQuery.setLogDesc(logDesc);
            request.setAttribute("logDesc", logDesc);
        }
        
        loginLogQuery.setPagerCount(pagerCount);
        loginLogQuery.setPagerOffset(pagerOffset);        
        systemLogService.querySystemLogList(loginLogQuery);
        
        
        return loginLogQuery;
    }
    
    /** 
     * @param pSystemLogService
     */
    public void setSystemLogService(SystemLogService pSystemLogService) {
        systemLogService = pSystemLogService;
    }

      
    
}